package com.example.drcbackend.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.drcbackend.Mapper.DbMapper;
import com.example.drcbackend.Mapper.SubsetdbMapper;
import com.example.drcbackend.entity.Subsetdb;
import com.example.drcbackend.jwt.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/results")
@RestController
@CrossOrigin
public class ResultController {
    @Autowired
    private SubsetdbMapper sm;
    @Autowired
    private DbMapper dm;
    @PostMapping("/checking_result")// 更新修复检查结果
    public Result checking_result(boolean result,int setid) {
        Subsetdb set=sm.selectById(setid);
        if(result){
        set.setResult(1);
        sm.updateById(set);}
        else {
            set.setResult(0);
            sm.updateById(set);
        }
        return Result.ok().message("修复检查更新成功");
    }
    @PostMapping("/all_result")// 获取所有修复检查结果
    public Result all_result() {
        LambdaQueryWrapper<Subsetdb> lqw=new LambdaQueryWrapper<>();
        List<Subsetdb> setdb=sm.selectList(lqw);
        for(Subsetdb record:setdb){
            record.setDb(dm.selectById(record.getDbid()));
        }


        return Result.ok().data("results",setdb);
    }
}
